var a = require("../../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../../@babel/runtime/regenerator")), t = require("../../../../@babel/runtime/helpers/asyncToGenerator"), e = require("../../../../mycomponent/payKeyboard/PayKeyboardAsync"), n = getApp();

Page({
    behaviors: [ e.payKeyboardAsync ],
    data: {
        popupSpecs: !1,
        language: "",
        usable: 0,
        sure_usable: "",
        radio: "1",
        Withdrawaltext: "提现",
        isclick: !0,
        balance_withdraw_status: "0",
        withdraw_status: 0,
        isConfirmBtn: !1,
        final_proportion_rate: 0,
        point: "积分"
    },
    onLoad: function(a) {
        this.usable = 0, this.sure_usable = "", this.customizeIncome();
        try {
            var t = wx.getStorageSync("yz_basic_info");
            t && this.setData({
                point: t.point
            });
        } catch (a) {}
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {
        this.getStoreInfo(), this.data.isclick = !0;
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getStoreInfo: function() {
        var a = this, t = this, e = n.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.withdraw.page");
        n._getNetWork({
            url: e,
            success: function(e) {
                var n = e.data;
                1 === n.result ? (t.setData({
                    Data: n.data,
                    withdraw_status: n.data.withdraw_status,
                    integralShow: n.data.integral_withdraw_status,
                    balance_withdraw_status: n.data.balance_withdraw_status,
                    coin: Number(t.data.sure_usable) * Number(n.data.withdraw_integral_scale) * Number(n.data.integral_withdraw_proportion / 100),
                    final_proportion_rate: n.data.final_proportion_rate
                }), 1 == n.data.balance_withdraw_status && (console.log("执行3"), a.setData({
                    radio: "3"
                })), 1 == n.data.integral_withdraw_status && (console.log("执行2"), a.setData({
                    radio: "2"
                })), 1 == n.data.withdraw_status && a.setData({
                    radio: "1"
                }), a.isShowConfirmBtn()) : wx.showToast({
                    title: n.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    isShowConfirmBtn: function() {
        (this.data.withdraw_status || this.data.integralShow || "1" == this.data.balance_withdraw_status || "1" == this.data.Data.we_chat_withdraw_status) && this.setData({
            isConfirmBtn: !0
        });
    },
    confirm: function() {
        var e = this;
        return t(a.default.mark(function t() {
            var o, i, s;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (e.data.isclick) {
                        a.next = 3;
                        break;
                    }
                    return wx.showToast({
                        title: "请勿重复点击",
                        icon: "none"
                    }), a.abrupt("return");

                  case 3:
                    if (e.data.isclick = !1, !(null == e.data.sure_usable || e.data.sure_usable <= 0)) {
                        a.next = 8;
                        break;
                    }
                    return wx.showToast({
                        title: "".concat(e.data.Withdrawaltext, "数值不可低于0"),
                        icon: "none"
                    }), e.data.isclick = !0, a.abrupt("return");

                  case 8:
                    if ("14" != e.data.radio || e.data.Data.lsp_wallet_site) {
                        a.next = 11;
                        break;
                    }
                    return wx.showModal({
                        content: "暂无钱包地址",
                        confirmText: "去设置",
                        success: function(a) {
                            a.confirm && wx.navigateTo({
                                url: "/packageI/walletSiteBind/walletSiteBind"
                            });
                        }
                    }), a.abrupt("return");

                  case 11:
                    if (o = {
                        change_value: e.data.sure_usable,
                        withdraw_type: e.data.radio
                    }, "14" != e.data.radio || !e.data.Data.need_password) {
                        a.next = 17;
                        break;
                    }
                    return a.next = 15, e.getPayKeyboardPassword();

                  case 15:
                    i = a.sent, o.password = i;

                  case 17:
                    s = n.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.withdraw.index"), 
                    n._getNetWork({
                        url: s,
                        data: o,
                        success: function(a) {
                            if (console.log(a, "数据"), 1 === a.data.result && "1" == a.data.data.withdraw_type) wx.navigateTo({
                                url: "/packageA/member/withdrawal/withdrawal"
                            }); else if (1 === a.data.result && "4" == a.data.data.withdraw_type) setTimeout(function() {
                                console.log("执行"), wx.navigateBack();
                            }, 1e3), wx.showToast({
                                title: a.data.msg,
                                icon: "none"
                            }); else {
                                if ("need register" == a.data.msg) return void ("10" != e.data.radio && "11" != e.data.radio && "12" != e.data.radio || wx.navigateTo({
                                    url: "/packageI/worker/type/type"
                                }));
                                e.data.isclick = !0, wx.showToast({
                                    title: a.data.msg,
                                    icon: "none"
                                });
                            }
                        },
                        fail: function(a) {
                            console.log(a);
                        }
                    });

                  case 19:
                  case "end":
                    return a.stop();
                }
            }, t);
        }))();
    },
    payKeyboardComplete: function(a) {
        this.setData({
            popupSpecs: !1
        }), e.payKeyboardAsync.complete(a.detail);
    },
    getPayKeyboardPassword: function() {
        var a = this;
        return this.setData({
            popupSpecs: !0
        }), new Promise(function(t, o) {
            e.payKeyboardAsync.addCompleteFn(function(e) {
                var o = n.getNetAddresss("payment.password.check");
                o += "&password=" + e, n._getNetWork({
                    url: o,
                    success: function(n) {
                        var o = n.data;
                        1 == o.result ? t(e) : (a.data.isclick = !0, wx.showModal({
                            title: "提示",
                            content: o.msg,
                            success: function(a) {
                                a.confirm && 2002 == o.data.code && wx.navigateTo({
                                    url: "/packageA/member/set_balance_password/set_balance_password"
                                });
                            }
                        }));
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            });
        });
    },
    onChange: function(a) {
        this.setData({
            sure_usable: a.detail
        });
    },
    customizeIncome: function() {
        try {
            var a = wx.getStorageSync("mailLanguage");
            if (a) {
                var t = JSON.parse(a);
                this.setData({
                    Withdrawaltext: t.income.name_of_withdrawal
                }), wx.setNavigationBarTitle({
                    title: t.income.name_of_withdrawal ? t.income.name_of_withdrawal : "提现"
                });
            }
        } catch (a) {}
    },
    onChangeRadio: function(a) {
        console.log(a), this.setData({
            radio: a.detail,
            discount_method: a.detail
        });
    }
});